extends "../cTDM/cTDM.gd"
func _info():
	pass

func _connect():
	._connect()

func _extInit():
	._extInit()
	chaName = "死徒"
	lv = 2
	attCoe.atk = 37 / 8.5 / 2
	attCoe.maxHp = 680 / 112.5 / 2
	attAdd.spd += 0.33
	addSkillTxt("奥术飞弹·暗：奥术飞弹附加暗属性，50%附加2层<中毒>，10%附加2层<中·毒>")
	addSkillTxt("死灵转换：当有友方角色[不包括召唤物和死灵]死在攻击范围内时，将其转换为死灵[继承25%攻击力，回复50%血量,一局最多转换5个]")
var changecnt = 0
var changelimit = 5 
func _onBattleStart():
	._onBattleStart()
	changecnt = 0
	changelimit = 5 
func _onCharaDel(cha):
	._onCharaDel(cha)
	#print(1)
	if self.isDeath:return
	var tcha = cha
	if cha.team != self.team:return
	if cha.isSumm:return
	if cha.get("ischange") == true || cha.get("ischange") == null :return
	if changecnt == changelimit:return
	if cha.isDeath && !cha.ischange && cha!=self && inrange(cha.cell,cell,att.atkRan):
		cst("死灵转换中","00FF00",tcha.position)
		var chas = tcha.getAllChas(1)
		for i in chas:
			if i.aiCha == tcha:
				i.aiCha = null
		yield(reTimer(0.01),"timeout")
		cst("死灵转换成功","00FF00",tcha.position)
		tcha.isDeath = false
		tcha.ischange = true
		changecnt += 1
		if sys.main.matCha(tcha.cell) != null:
			tcha.plusHp(tcha.att.maxHp * 0.5)
			tcha.revive(tcha.att.maxHp * 0.5)
			tcha.setCell(Vector2(0,5))
			tcha.position = sys.main.map.map_to_world(Vector2(0,5))
			tcha.aiCha = null
			#sys.main.setMatCha(Vector2(0,5),tcha)
		else:
			tcha.plusHp(tcha.att.maxHp * 0.5)
			tcha.revive(tcha.att.maxHp * 0.5)
			tcha.setCell(tcha.cell)
			tcha.position = sys.main.map.map_to_world(tcha.cell)
			tcha.aiCha = null
			#sys.main.setMatCha(tcha.cell,tcha)
		if tcha:
			tcha.attInfo.atk *= 0.25
			tcha.upAtt()
			
func inrange(cell1,cell2,r):
	var x = abs(cell1.x - cell2.x)
	var y = abs(cell1.y - cell2.y)
	return x*x + y*y <= r*r